package com.firefighting.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.firefighting.dao.PropriEnterMapper;
import com.firefighting.dao.ProprietorConnectorMapper;
import com.firefighting.dao.ProprietorMapper;
import com.firefighting.entity.Proprietor;

@Service
public class ProprietorService
{
	@Autowired
	private ProprietorMapper proprietorMapper;
	@Autowired
	private PropriEnterMapper propriEnterMapper;
	
	/*zhyan ����idɾ��ҵ����¼*/
	public int deleteById(int id)
	{
		return proprietorMapper.deleteByPrimaryKey(id);
	}
	
	@Autowired
	private ProprietorConnectorMapper  proConnector;
	//���� ���ҵ��
	public int addProprietor(Proprietor proprietor)
	{
		return proprietorMapper.insertSelective(proprietor);
	}
    //���� �༭ҵ����Ϣ
	public void editProprietor(Proprietor proprietor)
	{
		proprietorMapper.updateByPrimaryKeySelective(proprietor);
	}
    //���� �޸�ҵ����ϵ��
	public void updateProConnector(int conId, int id)
	{
		proConnector.updateProConnector(conId,id);
		
	}
	
	/**
	 * @author zhyan
	 * @param enterpriseId 
	 * @function ��ѯ���е�ҵ��
	 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryAllProprietor()
	{
		return proprietorMapper.selectAllProprietor();
	}
	
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryProprietorByEnter(Integer enterpriseId)
	{
		return proprietorMapper.selectProprietorByEnter(enterpriseId);
	}
	/**
	 * @author zhyan
	 * @function ����ҵ��id��ѯҵ����Ϣ
	 */
	public Proprietor queryProprietor(int id)
	{
		return proprietorMapper.selectByPrimaryKey(id);
	}
	
	/**
	 * @author zhyan
	 * @function ����ҵ����Ϣ
	 */
	public int updateProprietor(Proprietor record)
	{
		return proprietorMapper.updateByPrimaryKeySelective(record);
	}
	
	/**
	 * @author zhyan
	 * @function �����û����͵�ַ��ѯҵ����Ϣ
	 */
	public Proprietor queryWithNameAndAddress(String name, String address)
	{
		return proprietorMapper.selectByNameAndAddress(name, address);
	}
	
	/**
	 * @author zhyan
	 * @function �������ƺ͵�ַ��ѯid
	 */
	public int queryIdWithNameAndAddress(String name, String address)
	{
		return proprietorMapper.selectIdWithNameAndAddress(name, address);
	}
	/**
	 * @author Liuxc
	 * @function ������ҵ��ѯ����ҵ��ҵ��
	 * */
	public List<Proprietor> getProprietorByEnterprise(Integer enterpriseId) {
		// TODO Auto-generated method stub
		List<Integer> proprietorIdList = new ArrayList<Integer>();
		proprietorIdList = propriEnterMapper.selectIdByEnterId(enterpriseId);
		List<Proprietor> proprietorList = new ArrayList<Proprietor>();
		if(proprietorIdList.size()!=0){
			proprietorList = proprietorMapper.selectProprietorByIdList(proprietorIdList);
		}
		
		return proprietorList;
	}
	
	/**
	 * @author zhyan
	 * @function 根据项目负责人进行查询
	 * @date 2018.6.30
	 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryProprietorByLoginId(String account)
	{
		return proprietorMapper.selectProprietorByLoginId(account);
	}
	
	/**
	 * @author zhyan
	 * @function 根据企业id列表查询业主
	 * @date 2018.6.30
	 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryProprietorByEnterterpriseIdList(List<Integer> enterpriseIdList)
	{
		return proprietorMapper.selectProprietorByEnterterpriseIdList(enterpriseIdList);
	}
}